package com.agileai.crm.controller.procustomer;

import java.util.Date;
import java.util.List;

import com.agileai.crm.bizmoduler.procustomer.PerInfoManage;
import com.agileai.crm.common.PrivilegeHelper;
import com.agileai.domain.DataParam;
import com.agileai.domain.DataRow;
import com.agileai.hotweb.controller.core.StandardListHandler;
import com.agileai.hotweb.domain.FormSelectFactory;
import com.agileai.hotweb.domain.core.User;
import com.agileai.hotweb.renders.LocalRenderer;
import com.agileai.hotweb.renders.ViewRenderer;
import com.agileai.util.DateUtil;

public class PerInfoManageListHandler
        extends StandardListHandler {
    public PerInfoManageListHandler() {
        super();
        this.editHandlerClazz = PerInfoManageEditHandler.class;
        this.serviceId = buildServiceId(PerInfoManage.class);
    }
    public ViewRenderer prepareDisplay(DataParam param){
    	User user = (User) this.getUser();
		PrivilegeHelper privilegeHelper = new PrivilegeHelper(user);
		if (privilegeHelper.isInfoCollector()){
			setAttribute("doEdit8Save", true);
		}
		if (privilegeHelper.isTelNetSalesman()||privilegeHelper.isSalesDirector()){
			setAttribute("doDel", true);
		}
		mergeParam(param);
		initParameters(param);
		this.setAttributes(param);
		List<DataRow> rsList = getService().findRecords(param);
		this.setRsList(rsList);
		processPageAttributes(param);
		return new LocalRenderer(getPage());
	}
    protected void processPageAttributes(DataParam param) {
        setAttribute("PER_SEX",
                FormSelectFactory.create("PER_SEX")
                                 .addSelectedValue(param.get("PER_SEX")));
   initMappingItem("PER_SEX",
                   FormSelectFactory.create("PER_SEX").getContent());
   initMappingItem("PER_STATE",
           FormSelectFactory.create("PER_STATE").getContent());
   setAttribute("PER_STATE",
           FormSelectFactory.create("PER_STATE")
                            .addSelectedValue(param.get("PER_STATE")));
   this.setAttribute("currentTabId", param.get("currentTabId"));
   setAttribute("currentTabId",getAttributeValue("currentTabId", "0"));
    }

    protected void initParameters(DataParam param) {
        initParamItem(param, "PER_SEX", "");
        initParamItem(param, "PER_CREATER_NAME", "");
        initParamItem(param,"sdate","");
		initParamItem(param,"edate",DateUtil.getDateByType(DateUtil.YYMMDD_HORIZONTAL,DateUtil.getDateAdd(new Date(), DateUtil.DAY, 1)));
    }
    protected PerInfoManage getService() {
        return (PerInfoManage) this.lookupService(this.getServiceId());
    }
}
